package web;

import model.Algo;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

public class Beans extends AbstractPage{
	private static final long serialVersionUID = 1L;

	@SpringBean(name="algo")
	private Algo algo;
	private Component label;
	
	public Beans() {
		super();
		add(
			new Form<Void>("form").add(
				new TextField<String>("algo_field", new PropertyModel<String>(this, "algo.algo")),
				label = new Label("algo_label", new PropertyModel<String>(this, "algo.algo")),
				new AjaxButton("algo_cambiar") {
					private static final long serialVersionUID = 1L;

					@Override
					protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
						target.add(label);
					}
					
					@Override
					protected void onError(AjaxRequestTarget target, Form<?> form) {
						refrescarFeedback(target);
					}
				}
			)
		);
		label.setOutputMarkupId(true);
	}

	//getters&&setters
	public void setAlgo(Algo algo) {
		this.algo = algo;
	}
	public Algo getAlgo() {
		return algo;
	}
}